import * as bm from "/js/baseModule.js";
let Clipboard = require("/js/clipboard.js");

export class Module extends bm.baseModule {
    constructor(view) {
        super(view);

    }
    setReason(hasReason, data) {
        var that = this;
        var isHasReason = true;
        var feedData = {};
        if (hasReason != 1) {
            isHasReason = false;
            that.find(".btn").removeAttr("disabled");
        } else {
            isHasReason = true;
            that.find('.pull-right').removeClass('icon-checkmark-pc');
            that.find(".btn").attr("disabled", "false");

        }
        $.extend(true, feedData, data);

        this.vue = new Vue({
            el: '.FeedbackReason_vue',
            data: {
                isHasReason: isHasReason,
                feedback_data: feedData,
                tabType: 99,
            },
            computed: {
                oneDay: function () {
                    let startTime = globalData.current_demand.bid_win_at;
                    let stime = startTime * 1000;
                    let date = new Date().getTime();
                    let gapMin = Math.floor((date - stime) / 1000 / 60);
                    if (gapMin <= 0) {
                        //防止偶尔出现的js取时间不准确
                        gapMin = 1;
                    }

                    if (gapMin > (60 * 24)) {
                        return false;
                    }
                    return true;
                },
            }
        });

        that.wxTip = that.find(".tip-copy");
        /*一键复制插件初始化实例*/
        var clipboard = new Clipboard('.wx-code').on('success', function (e) {
            var e = e || window.event;
            console.log(e);
            that.wxTip.show();
            setTimeout(function () {
                that.wxTip.hide();
            }, 2000);
        }).on('error', function (e) { });

        that.find('.other').focus(function () {
            that.find('.text-hover').hide();
            console.log("foucs");
        });
        that.find('.other').blur(function () {
            console.log("blur");
            if ("" == that.find('.other').val().trim()) {
                that.find('.text-hover').show();
            }
        });
    }
    _evt_chooseTab(obj, hit) {
        if ($(hit).find('span').hasClass('pull-right')) {
            this.vue.tabType = $(hit).attr('type');
            this.find('.pull-right').removeClass('icon-checkmark-pc');
            $(hit).find('.pull-right').addClass('icon-checkmark-pc');
            this.find(".btn").removeAttr("disabled");
        }
    }

    // 提交原因
    _evt_submit() {
        let that = this;
        that.find('.sendImgPending').removeClass('hide');

        let data = {
            demand_id: globalData.current_demand.id,
            feedback: that.vue.tabType || 99,
            feedback_content: that.find(".other").val().trim(),
            feedback_type: 0
        };
        api.feedback(data, {
            succ: function (json) {
                // funs.tip('反馈成功', '您的反馈信息已提交，请等待微信公众号的审核结果通知', 'succ');
                console.log(JSON.stringify(data))
                globalData.current_demand.feedback_info.feedback_status = json.feedback_status;
                globalData.current_demand.my_offer = json.my_offer;
                // globalData.current_demand.my_follow_type = 3;
                that.find('.sendImgPending').addClass('hide');
                location.hash = 'project/FeedbackDemand/FeedbackResult';
            },
            fail: function (data) {
                that.find('.sendImgPending').addClass('hide');
                funs.tip(data.msg, '', 'fail');
            }
        });
    }
    _evt_closeSelf() {
        this.find('.text-hover').hide();
        this.find('.other').focus();
    }
    getData() {
        return this.vue.isHasReason || false;
    }
    _evt_loadRefunds() {
        location.hash = 'project/demand/Refunds';
    }

}
